package com.electromagnetic.industry.software.manage.service.serviceimpl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.electromagnetic.industry.software.common.enums.EffectFlagEnum;
import com.electromagnetic.industry.software.manage.mapper.EdFileFavoriteMapper;
import com.electromagnetic.industry.software.manage.pojo.models.EdFileFavorite;
import com.electromagnetic.industry.software.manage.service.EdFileFavoriteService;
import org.springframework.stereotype.Service;

@Service
public class EdFileFavoriteServiceImpl extends ServiceImpl<EdFileFavoriteMapper, EdFileFavorite> implements EdFileFavoriteService {

    /**
     * 逻辑删除
     *
     * @param userId
     * @param fileId
     * @return
     */
    @Override
    public boolean logicRemove(String userId, String fileId) {
        if (userId == null && fileId == null) {
            throw new IllegalArgumentException("必须提供至少一个参数");
        }
        LambdaUpdateWrapper<EdFileFavorite> updateWrapper = Wrappers.lambdaUpdate(EdFileFavorite.class)
                .set(EdFileFavorite::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code)
                .eq(userId != null, EdFileFavorite::getUserId, userId)
                .eq(fileId != null, EdFileFavorite::getFileId, fileId)
                .eq(EdFileFavorite::getEffectFlag, EffectFlagEnum.EFFECT.code);
        return update(updateWrapper);
    }

}
